package rents;

import java.io.Serializable;

import common.datetime.SimpleDate;
import common.money.MonetaryAmount;

public class User implements Serializable{
	
	private static final long serialVersionUID = -6310963906792344930L;

	private MonetaryAmount amount;

	private String creditCardNumber;

	private String merchantNumber;

	private SimpleDate date;

	
	public User(MonetaryAmount amount, String creditCardNumber, String merchantNumber, SimpleDate date) {
		this.amount = amount;
		this.creditCardNumber = creditCardNumber;
		this.merchantNumber = merchantNumber;
		this.date = date;
	}

	
	public static User createDining(String amount, String creditCardNumber, String merchantNumber) {
		return new User(MonetaryAmount.valueOf(amount), creditCardNumber, merchantNumber, SimpleDate.today());
	}

	
	public static User createDining(String amount, String creditCardNumber, String merchantNumber, int month,
			int day, int year) {
		return new User(MonetaryAmount.valueOf(amount), creditCardNumber, merchantNumber, new SimpleDate(month, day,
				year));
	}

	
	public MonetaryAmount getAmount() {
		return amount;
	}

	
	public String getCreditCardNumber() {
		return creditCardNumber;
	}

	
	public String getMerchantNumber() {
		return merchantNumber;
	}

	public SimpleDate getDate() {
		return date;
	}

	public boolean equals(Object o) {
		if (!(o instanceof User)) {
			return false;
		}
		User other = (User) o;
		// value objects are equal if their attributes are equal
		return amount.equals(other.amount) && creditCardNumber.equals(other.creditCardNumber)
				&& merchantNumber.equals(other.merchantNumber) && date.equals(other.date);
	}

	public int hashCode() {
		return amount.hashCode() + creditCardNumber.hashCode() + merchantNumber.hashCode() + date.hashCode();
	}

	public String toString() {
		return "Dining of " + amount + " charged to '" + creditCardNumber + "' by '" + merchantNumber + "' on " + date;
	}
	
	

}
